/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package my12306;

import java.beans.*;
import java.io.Serializable;
import my12306.table.KeyValueItem;

/**
 *
 * @author Jack
 */
public class OptionsBean implements Serializable {

    public static final String USER_AGENT_PROPERTY = "userAgentProperty";
    public static final String KEEP_ALIVE_PROPERTY = "keepALivetProperty";
    public static final String SLEEP_TIME_PROPERTY = "sleepTimeProperty";
    public static final String CHECKTICKET_PROPERTY = "checkTicket_PROPERTY";
//    public static final String BIGIPSERVEROTSWEB_PROPERTY = "BIGipServerotsweb_PROPERTY";
//    public static final String JSESSIONID_PROPERTY = "JSESSIONID_PROPERTY";
    public static final String BIGipServerotswebKey = "BIGipServerotsweb";
    public static final String COOKIES_PROPERTY = "cookiesProperty";
    public static final String JSESSIONIDKey = "JSESSIONID";
    public static final int KEEPALIVEDEFAULT = 15;
    public static final int SLEEPTIMEDEFAULT = 1;
    private KeyValueItem userAgent;
    private int keepAlive;
    private int sleepTime;
    private boolean checkTicket = true;
    private String bigipServerotsweb;
    private String jSessionID;
    private PropertyChangeSupport propertySupport;

    public OptionsBean() {
        propertySupport = new PropertyChangeSupport(this);
    }

    public KeyValueItem getUserAgent() {
        return userAgent;
    }

    /**
     * set the user-agent to use.
     *
     * @param value
     */
    public void setUserAgent(KeyValueItem value) {
        KeyValueItem oldValue = userAgent;
        userAgent = value;
        propertySupport.firePropertyChange(USER_AGENT_PROPERTY, oldValue, userAgent);
    }

    public void addPropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.addPropertyChangeListener(listener);
    }

    public void removePropertyChangeListener(PropertyChangeListener listener) {
        propertySupport.removePropertyChangeListener(listener);
    }

    /**
     * @return the keepLive(in minute)
     */
    public int getKeepLive() {
        return keepAlive;
    }

    /**
     * @param keepAlive Keep alive interval(in minute)
     */
    public void setKeepAlive(int value) {
        int oldValue = keepAlive;
        this.keepAlive = value;
        propertySupport.firePropertyChange(USER_AGENT_PROPERTY, oldValue, keepAlive);
    }

    /**
     * @return the sleepTime(in second)
     */
    public int getSleepTime() {
        return sleepTime;
    }

    /**
     * @param sleepTime the sleepTime to set(in second)
     */
    public void setSleepTime(int value) {
        int oldValue = sleepTime;
        this.sleepTime = value;
        propertySupport.firePropertyChange(USER_AGENT_PROPERTY, oldValue, sleepTime);
    }

    /**
     * @return the checkTicket
     */
    public boolean isCheckTicket() {
        return checkTicket;
    }

    /**
     * @param checkTicket the checkTicket to set
     */
    public void setCheckTicket(boolean value) {
        boolean oldValue = checkTicket;
        checkTicket = value;
        propertySupport.firePropertyChange(CHECKTICKET_PROPERTY, oldValue, checkTicket);
    }

    /**
     * @return the bigipServerotsweb
     */
    public String getBigipServerotsweb() {
        return bigipServerotsweb;
    }

//    /**
//     * @param value the bigipServerotsweb to set
//     */
//    public void setBigipServerotsweb(String value) {
//        String oldValue = bigipServerotsweb;
//        bigipServerotsweb = value;
//        propertySupport.firePropertyChange(BIGIPSERVEROTSWEB_PROPERTY, oldValue, bigipServerotsweb);
//    }
    /**
     * @return the jSessionID
     */
    public String getjSessionID() {
        return jSessionID;
    }

//    /**
//     * @param jSessionID the jSessionID to set
//     */
//    public void setjSessionID(String value) {
//        String oldValue = jSessionID;
//        jSessionID = value;
//        propertySupport.firePropertyChange(JSESSIONID_PROPERTY, oldValue, jSessionID);
//    }
    public void setCookies(String big, String session) {
        String[] oldValue = new String[]{getBigipServerotsweb(), getjSessionID()};
        bigipServerotsweb = big;
        jSessionID = session;
        String[] newValue = new String[]{getBigipServerotsweb(), getjSessionID()};
        propertySupport.firePropertyChange(COOKIES_PROPERTY, oldValue, newValue);
    }
}
